<?php

namespace app\model;

use think\facade\Cache;
use think\Model;

class CluePersonAllocationRecord extends Model
{
    /**
     * 人才生命周期表
     */

    protected $createTime='create_date';

    public function getUidAttr($name)
    {
        return [
            'id'=>$name,
            'text'=>(new User)->getIdNickName ($name)?:''
        ];
    }

    /**
     * 添加人才操作记录
     * @param $pid
     * @param $operate
     * @param $type
     * @return \app\model\CluePersonAllocationRecord|\think\Model
     */
    public function addPersonAllocationModel($pid,$operate,$uid,$type=1)
    {
        return self::create([
            'clue_p_id'=>$pid,
            'operate'=>$operate,
            'type'=>$type,
            'uid'=>$uid
        ]);
    }

    /**
     * 查询人才生命周期
     * @param $id
     * @param $type
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */

    public function getPersonCycleModel($id,$type=1): array
    {
        return $this->where (['clue_p_id'=>$id,'type'=>$type])->select()->toArray ();
    }
}